package com.ftm.dao.impl;

import java.util.List;

import com.ftm.dao.OrdersDao;
import com.ftm.entity.Goods;
import com.ftm.entity.Orders;
import com.ftm.tools.DBTools;
import com.ftm.tools.PageData;

/**
 * 
 * @author ZZP
 *
 */
public class OrdersDaoImpl implements OrdersDao{
	
	/**
	 * 新增订单 (完成测试)
	 */
	@Override
	public boolean addOrders(Orders orders) {
		String sql = "insert into ftm_order values(null,?,?,?,?,?)";
		return DBTools.exUpdate(sql,orders.getOrdersum(),orders.getOrderdate(),orders.getOrderstate()
				,orders.getUserid(),orders.getTotal())>0;
	}
	/**
	 * 删除订单(完成测试)
	 */
	@Override
	public boolean delOrders(int orderid) {
		String sql = "delete from ftm_order where orderid=?";
		return DBTools.exUpdate(sql, orderid) > 0;
	}
	/**
	 * 修改订单信息(完成测试)
	 */
	@Override
	public boolean upOrders(int ordersum, int orderstate, double total, int orderid) {
		String sql = "update ftm_order set ordersum=?,orderstate=?,total=? where orderid=?";
		return DBTools.exUpdate(sql,ordersum,orderstate,total,orderid)>0;
	}
	/**
	 * 修改订单状态(完成测试)
	 */
	@Override
	public boolean upOrdersState(int orderstate, int orderid) {
		String sql = "update ftm_order set orderstate =? where orderid=?";
		return DBTools.exUpdate(sql, orderstate, orderid) > 0;
	}
	/**
	 * 用户查看订单(完成测试)
	 */
	@Override
	public PageData<Orders> queryOrdersUserid(int page, int pageSize, int userid) {
		String sql = "select * from ftm_order where userid=?";
		return DBTools.exQueryByPage(sql, Orders.class, page, pageSize, userid);
	}
	/**
	 * 根据订单状态查询(完成测试)
	 */
	
	@Override
	public PageData<Orders> queryOrdersState(int page, int pageSize, int orderstate) {
		String sql = "select * from ftm_order where orderstate=?";
		return DBTools.exQueryByPage(sql, Orders.class, page, pageSize, orderstate);
	}
	/**
	 * 查看订单详情(完成测试)
	 */
	@Override
	public Orders queryOneOrders(int orderid) {
		String sql = "select * from ftm_order where orderid = ?";
		List<Orders> list = (List<Orders>) DBTools.exQuery(sql, Orders.class, orderid);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
	}

}
